import 'package:flutter/material.dart';
import 'package:jicaimao_flutter/utils/sp_key.dart';
import 'package:jicaimao_flutter/utils/sp_utils.dart';
import 'package:jicaimao_flutter/utils/utils.dart';
import 'package:jicaimao_flutter/views/tab_main_page.dart';

/// 引导页面
class SplashPage extends StatefulWidget {
  @override
  _SplashPage_State createState() => _SplashPage_State();
}

class _SplashPage_State extends State<SplashPage> {
  /// 引导图片集合
  List<String> _guideList = [
    'images/icon_one_round.png',
    'images/icon_two_round.png',
    'images/icon_three_round.png',
  ];

  List<Widget> _bannerList = new List();

  int _status = 0;

  var pageController = PageController();


  _SplashPage_State(){
    SpUtils.putBool(SpKey.KEY_SPLASH_MODEL,false);
  }


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
//    _initSplashData();
  }



  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop:_exitApp,
      child: Scaffold(
        backgroundColor: Colors.white,
        body: WillPopScope(
          onWillPop: _exitApp,
          child: PageView.builder(
              onPageChanged: _pageChange,
              controller: pageController,
              itemCount: 3,
              itemBuilder: (BuildContext context, int index) {
                if (index != 2) {
                  return Image.asset(
                    _guideList[index],
                    width: double.infinity,
                    height: double.infinity,
                  );
                } else {
                  return Stack(
                    children: <Widget>[
                      Image.asset(
                        _guideList[index],
                        width: double.infinity,
                        height: double.infinity,
                      ),
                      new Align(
                        alignment: Alignment.bottomCenter,
                        child: new Container(
                          margin: EdgeInsets.only(bottom: 160.0),
                          child: new RaisedButton(
                            textColor: Colors.white,
                            color: Colors.indigoAccent,
                            child: Text(
                              '立即体验',
                              style: new TextStyle(fontSize: 16.0),
                            ),
                            onPressed:goMain,
                          ),
                        ),
                      ),
                    ],
                  );
                }
              }),
        ),
      ),
    );
  }

  int _currentPageIndex = 0;

  void _pageChange(int index) {
    print("index:" + index.toString());
    print("_currentPageIndex:" + _currentPageIndex.toString());
    setState(() {
      if (index > _currentPageIndex) {
        _currentPageIndex = index;
      }
    });
  }
  goMain(){
    print("goMain");
    Navigator.pop(context);
    Navigator.push(
      context,
      MaterialPageRoute(
          builder: (context) => TabMainPage()),
    );

  }

  Future<bool> _exitApp() async {

  }
}
